"""数据处理模块"""
from typing import Dict, Any


def format_comment(raw_comment: Dict[str, Any]) -> Dict[str, Any]:
    """格式化评论数据"""
    comment_snippet = raw_comment.get("snippet", {})
    top_comment = comment_snippet.get("topLevelComment", {}).get("snippet", {})
    
    return {
        "comment_id": raw_comment.get("id", ""),
        "author_name": top_comment.get("authorDisplayName", "未知用户"),
        "comment_text": top_comment.get("textOriginal", ""),
        "like_count": top_comment.get("likeCount", 0),
        "publish_time": top_comment.get("publishedAt", ""),
        "update_time": top_comment.get("updatedAt", ""),
        "reply_count": comment_snippet.get("totalReplyCount", 0)
    }


def get_csv_fieldnames() -> list:
    """获取CSV文件的字段名"""
    return ["comment_id", "author_name", "comment_text", "like_count", 
            "publish_time", "update_time", "reply_count"]
    